Repository navigation
flatMap reads the array its callback gives and leaves it as it was - #99
Merged
Merged
Conversation
flatMap moved the elements out of the array the callback returned, which emptied one the callback did not make: the same array for every element, or a row of a table. [1, 2, 3].flatMap(v => pair) gave pair's elements once and left pair empty. It copies them now, as flat does. array_flatMap_shared.ts covers it on T[] and on Array<T>. It is marked "// not own": -mm=own refuses a callback that returns an array it does not own, so the case does not arise there. Tested in release on Windows x64 for gc, rc, none and own; debug, Linux, x86 and wasm were not built locally. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
flatMapno longer empties the array its callback returns. It copies the elements out, asflatdoes, where it moved them.Why
A callback that returned an array it kept had it drained on the first call: the same array for every element, or a row of a table.
Change
src/generics/lib.generics.ts: the loop in__Array.flatMappushes each element of the returned array.Array<T>.flatMapcalls it, so it is fixed too.tests/array_flatMap_shared.ts(new): a shared array, rows of a table, and theArray<T>class. It failed before the fix.For the reviewer
-mm=own: the new test is marked// not ownand skipped there. The compiler refuses a callback that returns an array it does not own ("borrows a captured variable"), so the bug could not occur under that model.flatMapwas already@sharesElements, so what own accepts is unchanged.Testing
🤖 Generated with Claude Code